package com.bilicraft;
import java.awt.*;

import javax.swing.*;
import res.Resources;

public class ServerList extends JPanel implements Runnable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public PanelLogin loginPanel;
	public Resources res;
	public Thread tTt;
	
	public Server[] sList = new Server[]{
			new Server("mc.bilicraft.com", 25565),
			new Server("beta125.bilicraft.com", 25565),
			new Server("218.95.101.94", 25565),
			new Server("211.101.12.153", 25565)
	}; 
	
	public ServerList(PanelLogin lp){
		loginPanel = lp;
		res = lp.res;
		tTt = new Thread(this);
		
		tTt.start();
	}
	
	public void paintComponent(Graphics g){
		g.drawImage(res.slbg, 0, 0, this);
		g.setColor(new Color(239, 239, 239));

		String[] s2 = new String[3];

		int yo = 104;
		for(Server s:sList){
			g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 16));
			g.drawString(s.ip+":"+s.port, 16, yo);
			s2 = s.status.split("\247");	
			g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
			g.drawString(s2[0]+"  "+s2[1]+"/"+s2[2], 16, yo+18);
			yo += 40;
		}
	}
	
	public void refresh(){
		for(Server s:sList){
			s.rests();
		}
		repaint();
		for(Server s:sList){
			s.getsts();
		}
		repaint();
	}
	
	public void run(){
		while(true){
			refresh();
			try{
				Thread.sleep(10000);
			}catch(InterruptedException ie){
				System.err.println("sleep.Error");
			}
		}
	}
	
}
